package org.zsl.mybatis.mapper;


import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.zsl.mybatis.model.Product;

import java.util.List;

@Mapper
public interface ProductMapper {
    @Select("select * from product")
    @Results(
            id="productMapper",
            value =  {// mapping 映射关系
                    @Result(column = "product_id",property = "productId"
                            ,jdbcType = JdbcType.INTEGER,id = true)
                    ,@Result(column = "name",property = "name",jdbcType = JdbcType.VARCHAR)
                    ,@Result(column = "price",property = "price" ,jdbcType = JdbcType.VARCHAR)
            }
    )
    List<Product> selectAll();


    @Select("select * from product where product_id=#{productId}")
    @ResultMap(value = "productMapper")
    Product selectById(Integer productId);

    /**
     * 动态查询/不定查询
     * */

    @Insert("insert into product(name,price) values(#{name},#{price})")
    int insert(Product product);


    @Update("update product set name=#{name},price=#{price} where product_id=#{productId}")
    int update(Product product);

    /**
     * 物理删除
     * */
    @Delete("delete from product where product_id = #{productId}")
    int delete(Integer productId);

    /**
     *  逻辑删除
     * */
    @Update("update product set isUsed=0 where product_id=#{productId}")
    int logicDelete(Integer productId);


    /**
     * 判断存在
     *   如何使用注解的方式实现
     * */
    List<Product>  exists(Product product);






}
